﻿package divinity.basic
{
	import flash.display.*;
	import flash.display.DisplayObject;
	import flash.events.Event;
	
	import divinity.basic.DivinityEngine;
	import divinity.fx.display.DisplayFX;
	import divinity.fx.particles.ParticleGenerator;
	import divinity.physics.Wind;
	import divinity.utils.Calculator;
	
	public class DivinityWorld extends DivinityEngine
	{
		
		private var _factions:Array=[];
		private var _objects:Array=[];
		private var _width:Number=800;
		private var _height:Number=600;
		private var _vfx:ParticleGenerator;
		
		protected var _calculator:Calculator=new Calculator();
		protected var _gravity:Number=0;
		private var _wind:Wind=new Wind(0,0,0);;
		protected var _terrain:BitmapData;
		private var _sunAngle:int=90;
		private var _sunStrength:Number=.7;
		//
		private var _display:Display;
		private var _displayFX:DisplayFX;
		
		public function DivinityWorld(god:*=null)
		{
			super(god);
			
			_display=new Display(1024,768);
			addChild(_display);
			
			_displayFX=new DisplayFX(this);	
			
				
			
		}		
		public function addObject(obj:*):void
		{
			log="adding object "+obj+" to world objects";
			_objects.push(obj);
		}
		/*
		*
		*
		*
		*
		*/
		
		
		
		/**
		 * 
		 * 
		 * 
		 * */
		
		public function get worldWidth():Number
		{
			return _width;
		}
		public function set worldWidth(w:Number):void
		{
			_width=w;
		}
		public function get worldHeight():Number
		{
			return _height;
		}
		public function set worldHeight(h:Number):void
		{
			_height=h;
		}
		
		
		public function get vfx():DisplayFX
		{
			return _displayFX;	
		}		
		
		/**
		 * 
		 * 
		 * 
		 * 
		 * 
		 * */
		public function get gravity():Number
		{
			return _gravity;
		}
		public function set gravity(value:Number)
		{
			_gravity=value;
		}
		public function get wind():Wind
		{
			return _wind;
		}
		public function set wind(value:Wind):void
		{
			_wind = value;
		}
		public function get terrain()
		{
			return _terrain;
		}
		public function getHeight(sx:Number,sy:Number)
		{
			var h:Number=_terrain.getPixel32(sx,sy);
			h=h&0xff;			
			return h;
		}
		public function getTerrain(sx:Number,sy:Number)
		{
			var h:Number=_terrain.getPixel32(sx,sy);
			h=h>>8&0xff;			
			return h;
		}
		public function getMovable(sx,sy)
		{
			var h:Number=_terrain.getPixel32(sx,sy);
			h=h>>24&0xff;
			var m:Boolean=h>0;
			
			return m;	
		}
		
		public function get sunAngle():int
		{
			return _sunAngle;
		}
		
		public function set sunAngle(value:int):void
		{
			_sunAngle = value;
		}
		
		public function get sunStrength():Number
		{
			return _sunStrength;
		}
		
		public function set sunStrength(value:Number):void
		{
			_sunStrength = value;
		}
		/**
		 * BACKGROUND container holds all sprites that are not interactive such as backgrounds, map modules and so on
		 * */
		public function get BACKGROUND():DivinityObject
		{
			return _display.background;
		}
		/**
		 * OBJECTS is a display container that shows all aobject on the scene that are not background, for ex. players, enemies,
		 * 
		 * */
		public function get OBJECTS():DivinityObject
		{
			return _display.objects;
		}
		/**
		 * VFX or Visual Effects, is container that holds all vfx sprites like particles, weapons and so on.
		 * */
		public function get VFX():DivinityObject
		{
			return _display.vfx;	
		}
		/**
		 * DISPLAY is a whole scene, with all visual layers(background, objects, vfx)
		 * 
		 * */
		public function get SCENE():DivinityObject
		{
			return _display.scene;
		}
		public function get DISPLAY()
		{
			return _display
		}
		public function get AIR()
		{
			return _display.air
		}
		public function get UI()
		{
			return _display.ui;
		}
		
		
		
	}
}